<?php

Print("
	<table cellpadding=0 cellspqcing=0 border=0 width=100%>
		<tr>
			<td valign=top width=50%>
");

	/*********************************************/
	if (@$_GET['etp'] == 1)
	{
		Print("<table cellpadding=0 cellspacing=0 border=0><tr><td><img src=\"$_SESSION[current_path]/images/step_1.png\" width=42 height=42></td><td>
		<b><font color=royalblue>1- Cr&eacute;ation du compte administrateur</font></b></td></tr></table>");
	}
	else
	{
		Print("<table cellpadding=0 cellspacing=0 border=0><tr><td><img src=\"$_SESSION[current_path]/images/step_1.png\" width=32 height=32></td><td>
		1- Cr&eacute;ation du compte administrateur</td></tr></table>");
	}
	/*********************************************/
	if (@$_GET['etp'] == 2)
	{
		Print("<table cellpadding=0 cellspacing=0 border=0><tr><td><img src=\"$_SESSION[current_path]/images/step_2.png\" width=42 height=42></td><td>
		<b><font color=royalblue>2- Cr&eacute;ation de la base</font></b></td></tr></table>");
	}
	else
	{
		Print("<table cellpadding=0 cellspacing=0 border=0><tr><td><img src=\"$_SESSION[current_path]/images/step_2.png\" width=32 height=32></td><td>
		2- Cr&eacute;ation de la base</td></tr></table>");
	}
	/*********************************************/
	if (@$_GET['etp'] == 3)
	{
		Print("<table cellpadding=0 cellspacing=0 border=0><tr><td><img src=\"$_SESSION[current_path]/images/step_3.png\" width=42 height=42></td><td>
		<b><font color=royalblue>3- Configuration du site</font></b></td></tr></table>");
	}
	else
	{
		Print("<table cellpadding=0 cellspacing=0 border=0><tr><td><img src=\"$_SESSION[current_path]/images/step_3.png\" width=32 height=32></td><td>
		3- Configuration du site</td></tr></table>");
	}
	/*********************************************/
	if (@$_GET['etp'] == 4)
	{
		Print("<table cellpadding=0 cellspacing=0 border=0><tr><td><img src=\"$_SESSION[current_path]/images/step_4.png\" width=42 height=42></td><td>
		<b><font color=royalblue>4- Installation termin&eacute;e</font></b></td></tr></table>");
	}
	else
	{
		Print("<table cellpadding=0 cellspacing=0 border=0><tr><td><img src=\"$_SESSION[current_path]/images/step_4.png\" width=32 height=32></td><td>
		4- Installation termin&eacute;e</td></tr></table>");
	}
	/*********************************************/
	
Print("
			</td>
			<td>
");

if (@$_GET['etp'] == 0)
{
	Print("
		Bienvenue sur le panneau d'installation de votre site.<br>
		Cet assistant va vous aidez &agrave; le configurer.<br>
		Cliquez sur le bouton ci-dessous pour commencer:<br>
		<form action=\"install.php?etp=1\" method=POST><input type=submit value=\"Commencer\"  onClick=\"this.form.submit();this.disabled=true;this.value='Initialisation...'\"></form>
	");
	if (@$_GET['err'] == 1)
	{
		$msg = "Erreur lors de la cr&eacute;ation de la configuration!<br>Si le probl&egrave;me persiste, veuilliez prendre contact avec le support UPP";
		$PWerr->sWarning($msg);
	}
}
elseif (@$_GET['etp'] == 1)
{
	$_SESSION['etp'] = "";
  $_SESSION['ok1'] = "ko";
	if (@$_GET['err'] == 1)
	{
		$msg = "Tous les champs sont obligatoires!";
		$PWerr->sWarning($msg);
	}
	elseif (@$_GET['err'] == 2)
	{
		$msg = "Les mots de passe doivent correspondre!";
		$PWerr->sWarning($msg);
	}
	elseif (@$_GET['err'] == 3)
	{
		$msg = "Adresse e-mail incorrecte!";
		$PWerr->sWarning($msg);
	}
	Print("
	    <form action=\"install.php?etp=2\" method=POST>");
      $_SESSION['etp'] = "etpadmin";
      Print("<table cellpadding=0 cellspacing=3 border=0>
        <tr>
          <td>Administrateur :</td>
          <td><input type=text name=\"admin\" size=15></td>
          <td><img src=\"$_SESSION[current_path]/images/user_1.png\" width=16 height=16></td>
        </tr>
        <tr>
          <td>Mot de passe :</td>
          <td><input type=password name=\"passadmin\" size=15></td>
          <td><img src=\"$_SESSION[current_path]/images/secu_1.png\" width=16 height=16></td>
        </tr>
        <tr>
          <td>Confirmation :</td>
          <td><input type=password name=\"pass2admin\" size=15></td>
          <td></td>
        </tr>
        <tr>
          <td>Adresse E-Mail :</td>
          <td><input type=text name=\"mailadmin\" size=15></td>
          <td><img src=\"$_SESSION[current_path]/images/mail_1.png\" width=16 height=16></td>
          <td><input type=submit value=\"Suivant >\"  onClick=\"this.form.submit();this.disabled=true;this.value='V&eacute;rification...'\"></td>
        </tr>
      </table>
      <br>
      </form>
	");
}
elseif (@$_GET['etp'] == 2)
{
	$_SESSION['ok2'] = "ko";
	if ($_SESSION['etp'] != "etpadmin")
	{
		redirect('install.php');
		exit;
	}
	if ($_SESSION['ok1'] == "ko")
	{
		if ((trim($_POST['passadmin']) == "") || (trim($_POST['pass2admin']) == "") || (trim($_POST['mailadmin']) == ""))
		{
			redirect('install.php?etp=1&err=1');
			exit;
		}
		if (is_email(trim($_POST['mailadmin'])) == -1)
		{
			redirect('install.php?etp=1&err=3');
			exit;
		}
		if (trim($_POST['passadmin']) != trim($_POST['pass2admin']))
		{
			redirect('install.php?etp=1&err=2');
			exit;
		}
		$_SESSION['infos_admin'] = trim($_POST['admin']);
    $_SESSION['infos_passadmin'] = trim($_POST['passadmin']);
    $_SESSION['infos_mailadmin'] = trim($_POST['mailadmin']);
    $_SESSION['ok1'] = "ok";
	}
	if (@$_GET['err'] == 1)
	{
		$msg = "Il manque des informations!";
		$PWerr->sWarning($msg);
	}
	elseif (@$_GET['err'] == 2)
	{
		$msg = "Imposible de se connecter au serveur!";
		$PWerr->sWarning($msg);
	}
	elseif (@$_GET['err'] == 3)
	{
		$msg = "Imposible de cr&eacute;er la base et les tables!";
		$PWerr->sWarning($msg);
	}
	elseif (@$_GET['err'] == 4)
	{
		$msg = "Imposible de cr&eacute;er le fichier de configuration!<br>V&eacute;rifi&eacute; les droits en &eacute;criture du dossier \"<b>./data</b>\"";
		$PWerr->sWarning($msg);
	}	
	Print("
			<form action=\"install.php?etp=3\" method=POST>");
      $_SESSION['etp'] = "etpmysql";
      Print("<h4>Informations root</h4>
      <table cellpadding=0 cellspacing=3 border=0>
        <tr>
          <td>Root :</td>
          <td><input type=text name=\"user_root\" value=\"root\" size=15></td>
          <td><img src=\"$_SESSION[current_path]/images/user_1.png\" width=16 height=16></td>
        </tr>
        <tr>
          <td>Mot de passe :</td>
          <td><input type=password name=\"pass_root\" size=15></td>
          <td><img src=\"$_SESSION[current_path]/images/secu_1.png\" width=16 height=16></td>
        </tr>
      </table>
      <br>
      <h4>Informations sur la base</h4>
      <table cellpadding=0 cellspacing=3 border=0>
		<tr>
          <td>Serveur :</td>
          <td><input type=text name=\"server_name\" value=\"localhost\" size=15></td>
          <td><img src=\"$_SESSION[current_path]/images/server_1.png\" width=16 height=16></td>
        </tr>
        <tr>
          <td>Nom de la base :</td>
          <td><input type=text name=\"base_name\" size=15></td>
          <td><img src=\"$_SESSION[current_path]/images/base_1.png\" width=16 height=16></td>
        </tr>
        <tr>
          <td>Prefixe tables :</td>
          <td><input type=text name=\"tables_prefixe\" size=15 value=\"odtpw_\"></td>
          <td><img src=\"$_SESSION[current_path]/images/base_2.png\" width=16 height=16></td>
        </tr>
      </table>
      <br>
      <h4>Informations d'identification des utilisateurs</h4>
      <table cellpadding=0 cellspacing=3 border=0>
		<tr>
          <td><input type=radio name=\"users_auth\" value=\"mysql\" checked> MySQL</td>
          <td><input type=radio name=\"users_auth\" value=\"LDAP\"> LDAP</td>");
          #<td><input type=radio name=\"users_auth\" value=\"WLS\"> Windows Live Services</td>
          Print("<td><img src=\"$_SESSION[current_path]/images/user_2.png\" width=16 height=16></td>
        </tr>
        <tr>
					<td><input type=submit value=\"Suivant >\"  onClick=\"this.form.submit();this.disabled=true;this.value='V&eacute;rification...'\"></td>
        </tr>
      </table>
      <br>
      </form>
	");
}
elseif (@$_GET['etp'] == 3)
{
	if ($_SESSION['etp'] != "etpmysql")
	{
		redirect('install.php');
		exit;
	}
	if ($_SESSION['ok2'] == "ko")
	{
		if ((trim($_POST['user_root']) == "") || (trim($_POST['server_name']) == "") || (trim($_POST['base_name']) == ""))
		{
			$_SESSION['etp'] = "etpadmin";
			redirect('install.php?etp=2&err=1');
			exit;
		}
		if (test_connection($_POST['server_name'], $_POST['user_root'], $_POST['pass_root']) == -1)
		{
			$_SESSION['etp'] = "etpadmin";
			redirect('install.php?etp=2&err=2');
			exit;
		}
		$get_result = create_base($_POST['server_name'], $_POST['user_root'], $_POST['pass_root'], $_POST['base_name'], $_POST['tables_prefixe'], $_POST['users_auth']);
		if ($get_result == -1)
		{
			$_SESSION['etp'] = "etpadmin";
			redirect('install.php?etp=2&err=2');
			exit;
		}
		if ($get_result == -2)
		{
			$_SESSION['etp'] = "etpadmin";
			redirect('install.php?etp=2&err=3');
			exit;
		}
		elseif ($get_result == -3)
		{
			$_SESSION['etp'] = "etpadmin";
			redirect('install.php?etp=2&err=4');
			exit;
		}
		$_SESSION['users_auth'] = $_POST['users_auth'];
		$_SESSION['ok2'] = "ok";
	}
	if (@$_GET['err'] == 1)
	{
		$msg = "Informations sur le domaine erron&eacute;e!";
		$PWerr->sWarning($msg);
	}
	elseif (@$_GET['err'] == 2)
	{
		$msg = "Vous devez au moins renseigner un titre pour votre site!";
		$PWerr->sWarning($msg);
	}
	elseif (@$_GET['err'] == 3)
	{
		$msg = "Imposible de cr&eacute;er le fichier de configuration!<br>V&eacute;rifi&eacute; les droits en &eacute;criture du dossier \"<b>./data</b>\"";
		$PWerr->sWarning($msg);
	}
	Print("
			<form action=\"install.php?etp=4\" method=POST>");
      $_SESSION['etp'] = "etpconfig";
      Print("<h4>Informations sur votre site</h4>
      <table cellpadding=0 cellspacing=3 border=0>
        <tr>
          <td>Titre :</td>
          <td><input type=text name=\"site_title\" size=15></td>
        </tr>
        <tr>
          <td>Slogan :</td>
          <td><input type=text name=\"site_subtitle\" size=15></td>
        </tr>
      </table>
      <br>
	");
	if ($_SESSION['users_auth'] == "LDAP")
	{
		Print("
			<h4>Informations sur le serveur LDAP</h4>
			<table cellpadding=0 cellspacing=3 border=0>
        <tr>
          <td>Serveur :</td>
          <td><input type=text name=\"server_ldap\" size=15></td>
          <td><img src=\"$_SESSION[current_path]/images/server_2.png\" width=16 height=16></td>
        </tr>
        <tr>
          <td>Domaine :</td>
          <td><input type=text name=\"domain_ldap\" size=15></td>
          <td><img src=\"$_SESSION[current_path]/images/domain_1.png\" width=16 height=16></td>
        </tr>
      </table>
      <br>
		");
	}
	Print("
		<table cellpadding=0 cellspacing=3 border=0>
			<tr>
				<td><input type=submit value=\"Suivant >\"  onClick=\"this.form.submit();this.disabled=true;this.value='Cr&eacute;ation du site en cours...'\"></td>
			</tr>
		</table>
		</form>
	");
}
elseif (@$_GET['etp'] == 4)
{
	if ($_SESSION['etp'] != "etpconfig")
	{
		Print("<script language=JavaScript>setTimeout(\"document.location = 'install.php'\", 1)</script>");
		redirect('install.php');
		exit;
	}
	if ($_SESSION['users_auth'] == "LDAP")
	{
		if ((trim($_POST['server_ldap']) == "") || (trim($_POST['domain_ldap']) == ""))
		{
			$_SESSION['etp'] = "etpmysql";
			redirect('install.php?etp=3&err=1');
			exit;
		}
	}
	if (trim($_POST['site_title']) == "")
	{
		$_SESSION['etp'] = "etpmysql";
		redirect('install.php?etp=3&err=2');
		exit;
	}
	if ($_SESSION['users_auth'] == "LDAP")
	{
		if (create_config_ldap(trim($_POST['server_ldap']), trim($_POST['domain_ldap'])) == -1)
		{
			$_SESSION['etp'] = "etpmysql";
			redirect('install.php?etp=3&err=3');
			exit;
		}
	}
	if (create_config_default(trim($_POST['site_title']), trim($_POST['site_subtitle']), $_SESSION['users_auth']) == -1)
	{
		$_SESSION['etp'] = "etpmysql";
		redirect('install.php?etp=3&err=3');
		exit;
	}
	if (apply_config() == -1)
	{
		$_SESSION['etp'] = "";
		redirect('install.php?err=1');
		exit;
	}
	$msg = "Installation termin&eacute;e avec succ&egrave;s!<br>Veuillez patientez...";
	$PWerr->setSize('b');
	$PWerr->sNotice($msg);
	session_destroy();
	redirect('index.php', 5000);
}

Print("
			</td>
		</tr>
	</table>
");

?>